<template>
  <div id="app" :class="{ wrapperBgColor: isAddClass }">
    <Header
      v-if="!isIndexPage"
      :isShow="isShow"
      :isPrivacyPage="isPrivacyPage"
    ></Header>
    <router-view />
  </div>
</template>

<script>
// import Vue from "vue";
import Header from "@/components/Header.vue";
import localDb from "./utils/localDb.js";
export default {
  components: {
    Header,
  },
  data() {
    return {
      isAddClass: false,
      routesData: [],
      path: "default",
      isRegister: false,
      isRouterAlive: true,
      isShow: false,
      isIndexPage: false,
      // isFromDelay: false,
      isPrivacyPage: true,
    };
  },
  methods: {
    //设置页面
    setPage() {
      this.routesData = this.$router.options.routes;
      this.routesData.forEach((v) => {
        // 判断是否显示页头
        if (v.path == "/privacy" || v.path == "/empty" || v.path == "/error") {
          // this.$refs.head.isPrivacyPage = false;
          this.isPrivacyPage = false;
        } else {
          this.isPrivacyPage = true;
        }

        if (v.path === "/") {
          this.isIndexPage = true;
          this.isShow = true;
        } else {
          this.isIndexPage = false;
          this.isShow = false;
        }

        if (v.path == "/" || v.path == "/error") {
          this.isAddClass = false;
        } else {
          this.isAddClass = true;
        }
      });
    },
    reload() {
      this.isRouterAlive = false;
      this.$nextTick(function () {
        this.isRouterAlive = true;
      });
    },
  },
  computed: {},
  created() {},
  mounted() {
    this.setPage();
  },
  provide() {
    return {
      reload: this.reload,
    };
  },
  updated: function () {
    let path = this.$route.path;
    // 判断是否显示页头
    if (path == "/privacy" || path == "/empty" || path == "/error") {
      this.isPrivacyPage = false;
    } else {
      this.isPrivacyPage = true;
    }

    if (path === "/") {
      this.isIndexPage = true;
      this.isShow = true;
    } else {
      this.isIndexPage = false;
      this.isShow = false;
    }

    if (path == "/" || path == "/error") {
      this.isAddClass = false;
    } else {
      this.isAddClass = true;
    }
  },
};
</script>
<style lang="scss">
#app {
  position: relative;
  min-height: 100%;
  &.wrapperBgColor {
    background-color: #edf4fa;
  }
}
</style>
